﻿@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title></title>
    <link rel="stylesheet" type="text/css" href="/admin/EasyUi/themes/default/easyui.css" />
    <link rel="stylesheet" type="text/css" href="/admin/EasyUi/themes/icon.css" />

    <script type="text/javascript" src="/admin/Common/Scripts/jquery-1.12.0.min.js"></script>
    <script type="text/javascript" src="/admin/EasyUi/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="/admin/EasyUi/locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="/admin/Common/Scripts/Utils.js"></script>
</head>
<body>
    <div>
        <style type="text/css">
            .box {
                border: 1px solid #bbb;
                background: #eee;
                margin-top: 0;
                margin-bottom: 10px;
                padding: 5px;
                line-height: 36px;
            }

                .box .title {
                    background: #eee;
                    height: 36px;
                    font-weight: normal;
                }

                    .box .title .tip {
                        font-weight: bold;
                        margin-right: 8px;
                        padding: 0 3px;
                        cursor: pointer;
                    }

                    .box .title .handle {
                        float: right;
                        margin-right: 10px;
                    }

                .box .content {
                    border-top: 1px solid #bbb;
                    padding-left: 30px;
                    display: block;
                }
        </style>

        @{
            var Catalog = ViewBag.Catalog;
            var ParentCatalog = ViewBag.ParentCatalog;
            var editType = Catalog.CatalogId > 0 ? "物料分类操作：<strong>修改</strong>" : "物料分类操作：<strong>新增</strong>";
            var num = 1;
            
        }


        <script type="text/javascript">
            @*$(function () {
                $("*").click(function () {
                    if (parent)
                        parent.dyniframesize();
                })
            });
            var msg = "@message";
            if (msg) {
                alert(msg);
            }*@
        </script>



        <div class="easyui-panel" data-options="height:'30px'">

            <a id="btn_reload" href="javascript: location.href='CatalogEdit?operation=add&parentId=0&catalogId=0';" class="easyui-linkbutton" style="width:110px;height:30px" data-options="iconCls:'icon-add'">添加一级分类</a>
     
            @if (Catalog.CatalogId > 0)
            {
                <a id="btnDelete" href="javascript: DetMenuFun(@(Catalog.CatalogId),@(Catalog.ParentId),'@(Catalog.IsParent)');" class="easyui-linkbutton" style="width:110px;height:30px" data-options="iconCls:'icon-remove'">删除当前分类</a>
            }
            @if (Catalog.IsParent && !Catalog.IsStop && !Catalog.IsDeleted)
            {
                <a id="addSub" href="javascript: location.href='CatalogEdit?operation=add&parentId=@(Catalog.CatalogId)&catalogId=0';" class="easyui-linkbutton" style="width:110px;height:30px" data-options="iconCls:'icon-add'">添加子分类</a>
            }
        </div>

        <form id="editform" action="DoEditCatalog" method="post">
            <div class="easyui-panel" title="@editType" data-options="fit:false">

                <table id="dg" class="easyui-datagrid" data-options="showHeader:false,singleSelect:true,checkOnSelect:false,striped:true" style="width:100%;">
                    <thead>
                        <tr>
                            <th data-options="field:'code',align:'right'" style="width:30%">标题</th>
                            <th data-options="field:'name'" style="width:70%">内容</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td style="text-align:right;">分类ID：</td>
                            <td style=" background-color:#fff;">
                                <input id="catalogId" name="catalogId" type="text" hidden="hidden" value="@(Catalog.CatalogId)" />
                                <input id="parentId" name="parentId" type="text" hidden="hidden" value="@(Catalog.ParentId)" />

                                @if (Catalog.CatalogId == 0)
                                {
                                    <div>无</div>
                                }
                                else
                                {
                                    <div>@Catalog.CatalogId</div>;
                                }
                            </td>
                        </tr>

                        <tr>
                            <td style="background-color:#fff;text-align:right;">分类名称：</td>
                            <td style=" background-color:#fff;">
                                <input id="catalogName" name="catalogName" type="text" value="@(Catalog.CatalogName)" />&nbsp;<span style="color:red">*</span>

                                @if (Catalog.IsStop)
                                {
                                    <input id="stopFlog" name="stopFlog" value="" onclick="stopFlogf(this)" type="checkbox" checked="checked" />
                                    <input id="oldStopFlog" name="oldStopFlog" hidden="hidden" type="number" value="1" />
                                }
                                else
                                {
                                    <input id="stopFlog" name="stopFlog" value="" onclick="stopFlogf(this)" type="checkbox" />
                                    <input id="oldStopFlog" name="oldStopFlog" hidden="hidden" type="number" value="0" />
                                }
                                停用

                            </td>
                        </tr>
                        <tr>
                            <td style="background-color:#fff;text-align:right;">分类排序：</td>
                            <td style=" background-color:#fff;">
                                <input id="sortOrder" name="sortOrder" type="text" value="@(Catalog.SortOrder)" />
                            </td>
                        </tr>
                        <tr>
                            <td style=" background-color:#fff; text-align:right;">上级分类：</td>
                            <td style=" background-color:#fff;">
                                @(Catalog.SuperiorName)&nbsp;@(Catalog.ParentName)
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>

            <div class="easyui-panel" title="" data-options="">
                <div class="easyui-panel" data-options="noheader:true" style="text-align:center">
                    <a id="btn" href="javascript: Submit()" class="easyui-linkbutton" style="width:100px;height:30px" data-options="">保存</a>
                </div>

            </div>

            <div id="fsUploadProgress"> </div>
        </form>


        <script language="javascript" type="text/javascript">

            //新增行数据
            function addRow(target) {
                $("#dg").datagrid
            }
            function delCount(inputId) {

            }
            function resizeForm() {
                //界面变高后,需要重新调整frame的高度,
                try {
                    if (parent)
                        parent.dyniframesize();
                }
                catch (e) { }
            }

            function stopFlogf(p) {

                if ($(p).attr("checked") == "checked") {
                    $(p).attr("value", 0);
                    $(p).attr("checked", "");
                }
                else {
                    $(p).attr("value", 1);
                    $(p).attr("checked", "checked");
                }
            }

            function Submit() {
                $('#editform').form("submit", {
                    url: "DoEditCatalog",
                    onSubmit: function () {
                        var isval = SubmitForm();
                        if (!isval)
                            $.messager.progress('close');
                        return isval;
                    },
                    success: function (data) {
                        $.messager.progress('close');
                        var obj = eval("(" + data + ")");
                        alert(obj.msg);
                        if (obj.success) {
                            //刷新菜单分类
                            window.parent.frames["leftFrame"].location.reload();
                            window.parent.location.reload();
                        }
                    }
                });
            }

            function SubmitForm() {
                if (!jQuery.trim($("#catalogName").val())) {
                    alert("请输入分类名称！");
                    return false;
                }
                if (!jQuery.trim($("#sortOrder").val())) {
                    alert("请输入分类排序值")
                    return false;
                }

                return true;
            }

         
            function DetMenuFun(catalogId, parentId, isParent) {
                if (confirm("确定删除该分类?")) {
                    jQuery.ajax({
                        type: "post",
                        url: "DoDeleteCatalog?catalogId=" + catalogId + "&parentId=" + parentId,
                        dataType: "json",
                        data: { "catalogId": catalogId, "parentId": parentId },
                        success: function (data) {
                            if (data.success) {
                                //刷新菜单分类
                                window.parent.frames["leftFrame"].location.reload();
                                //刷新当前界面
                                window.location.href = "CatalogEdit?operation=add&parentId=0&catalogId=0";
                            }
                            alert(data.msg);
                        },
                        error: function () { alert("error"); }
                    });
                }
            }

            //生成关联url 序号
            function sortNum(box) {
                var initNum = 1;
                box.find(".content").find("i").each(function () {
                    $(this).text(initNum++);
                })
            }

        </script>

    </div>
</body>
</html>
